package com.yxj.MyThreadPoll1;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MyThreadPoll2 {
    public static void main(String[] args) throws InterruptedException {
        /*
        * public static ExecutorService newCachedThreadPoll(); 创建一个没有上限的线程池
        * public static ExecutorService newFixedThreadPoll(int nThreads); 创建一个有上限的线程池*/

        //获取线程池对象
        //ExecutorService poll1 = Executors.newCachedThreadPool();
        ExecutorService poll1 = Executors.newFixedThreadPool(2);
        //2.提交任务
        poll1.submit(new MyRunnable());
        Thread.sleep(1000);
        poll1.submit(new MyRunnable());
        Thread.sleep(1000);

        poll1.submit(new MyRunnable());
        Thread.sleep(1000);

        poll1.submit(new MyRunnable());
        Thread.sleep(1000);


        //3.销毁线程池
        poll1.shutdown();
    }
}
